home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5537 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: (void(far *)()) 0
  5. Date: 08 Feb 1996 15:54:17 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb8085417@qcd.lanl.gov>
  8. References: <341998718.10858110@magnet.at> <31165B9D.398E@imsisoft.com>
  9.     <4f66c0$cn0@solutions.solon.com> <3118F813.41BF@imsisoft.com>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: Victor Bazarov's message of Wed, 07 Feb 1996 11:05:55 -0800
  14.  
  15. In article <3118F813.41BF@imsisoft.com> Victor Bazarov
  16. <vbazarov@imsisoft.com> writes: 
  17. <snip>
  18.    > 0 is a special case.  Zero cast to a pointer type is a null
  19. pointer of that 
  20.    > type.  Or rather, *a constant zero* is.  An integer with value zero may
  21.    > produce different results.
  22.  
  23.    As I undestood, this "may produce different results":
  24.  
  25.    typedef void (far *pVOIDVOID)();
  26.    int zero = 0;
  27.    pVOIDVOID funky;
  28.    funky = (void(far *)()) zero;
  29.  
  30.    than
  31.  
  32.    typedef void (far *pVOIDVOID)();
  33.    pVOIDVOID funky;
  34.    funky = (void(far *)()) 0;
  35.  
  36.    ?
  37.  
  38. I do not know: the `far' there is a syntax error! Assuming #define far
  39. at the beginning of the code:
  40.  
  41. The former is implementation defined behaviour: what happens
  42. depends on the documentation provided by the implementation. There is
  43. no guarantee that funky does or does not point to an actual function
  44. defined in the program.
  45.  
  46. In the second case, the behaviour is defined by the standard. funky is
  47. guaranteed now to be a _valid_ pointer and it is guaranteed to compare
  48. unequal to the address of every function in the code.
  49.  
  50.    > A textual zero, cast to pointer type, points at no object; this is magic.
  51.  
  52. Not only textual zeroes but a class of expressions called integral
  53. constant expressions that evaluate to zero. These are all constant
  54. expressions of integral types which can be evaluated without accessing
  55. any variable (not even const qualified variables), string literal or
  56. making a function call, and which do not involve floating point
  57. arithmetic or the value of addresses of objects. Examples are (1-1)
  58. and (sizeof("a")-2) etc.
  59.  
  60. Cheers
  61. Tanmoy
  62. --
  63. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  64. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  65. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  66. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  67. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  68. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  69.